// 多语言配置
const translations = {
    zh: {
        // 导航栏
        nav_portfolio: '我的作品集',
        nav_about: '👤 关于我',
        nav_works: '🎨 作品',
        nav_contact: '📧 联系方式',
        
        // 英雄区域
        hero_greeting: '你好，我是',
        hero_title: 'Python开发者',
        hero_welcome: '欢迎访问我的个人作品集网站',
        hero_view_works: '查看我的作品',
        
        // 关于我
        about_title: '关于我',
        about_role: 'Python Developer',
        about_description1: '我是一名专注于消息中间件、实时数据处理和高可用架构设计的Python开发者。拥有丰富的大规模系统开发经验，擅长构建高性能、可扩展的后端服务。',
        about_description2: '在技术之外，我喜欢Rust编程语言，热爱动漫文化，特别喜欢《幸运星》、《孤独摇滚》和《摇曳露营》等作品。我相信技术与艺术的结合能够创造出更好的产品。',
        about_skills: '技能专长',
        about_experience: '专业经历',
        about_achievements: '个人成就',
        
        // 技能标签
        skill_expert: '专家级',
        skill_proficient: '熟练级',
        skill_beginner: '入门级',
        
        // 时间线
        timeline_tsinghua: '清华大学',
        timeline_tsinghua_major: '计算机科学与技术专业 · 本科',
        timeline_stanford: '斯坦福大学',
        timeline_stanford_major: '计算机科学专业 · 硕士',
        timeline_google: 'Google',
        timeline_google_role: '软件工程师 · 负责分布式系统开发',
        timeline_openai: 'OpenAI',
        timeline_openai_role: '软件工程师 · AI基础设施开发',
        
        // 成就
        achievement_tsinghua: '清华大学优秀毕业生',
        achievement_tsinghua_year: '2014年度优秀毕业生',
        achievement_mvp: '微软MVP',
        achievement_mvp_desc: 'Microsoft Most Valuable Professional',
        achievement_huawei: '华为开发者认证',
        achievement_huawei_desc: '高级软件工程师认证',
        
        // 作品展示
        works_title: '我的作品',
        work1_title: '现代电商平台UI设计',
        work1_desc: '为时尚品牌打造的全新电商平台界面，采用简洁现代的设计风格，优化用户购物体验。项目包含完整的用户流程设计、响应式布局以及品牌视觉识别系统。',
        work2_title: '科技企业官网开发',
        work2_desc: '为科技创新公司开发的官方网站，采用React框架构建，实现了流畅的动画效果、完善的内容管理系统以及SEO优化，大幅提升了网站的访问量和转化率。',
        work3_title: '健康管理移动应用',
        work3_desc: '设计并开发的健康追踪移动应用，包含运动记录、饮食管理、健康数据分析等功能。采用Material Design设计原则，界面直观易用，深受用户好评。',
        
        // 联系方式
        contact_title: '与我联系',
        contact_subtitle: '有任何问题或合作意向，欢迎通过以下方式联系我',
        contact_name: '姓名',
        contact_email: '邮箱',
        contact_message: '留言',
        contact_send: '发送消息',
        contact_email_title: '邮箱',
        contact_website: '个人网页',
        contact_address: '地址',
        contact_location: '中国 北京',
        
        // 页脚
        footer_copyright: '个人作品集. 保留所有权利.',
        footer_website: '个人网页',
        footer_email: '邮箱',
        footer_contact: '联系方式'
    },
    en: {
        // 导航栏
        nav_portfolio: 'My Portfolio',
        nav_about: '👤 About Me',
        nav_works: '🎨 Works',
        nav_contact: '📧 Contact',
        
        // 英雄区域
        hero_greeting: 'Hello, I am',
        hero_title: 'Python Developer',
        hero_welcome: 'Welcome to my personal portfolio website',
        hero_view_works: 'View My Works',
        
        // 关于我
        about_title: 'About Me',
        about_role: 'Python Developer',
        about_description1: 'I am a Python developer specializing in message middleware, real-time data processing, and high-availability architecture design. With extensive experience in large-scale system development, I excel at building high-performance, scalable backend services.',
        about_description2: 'Beyond technology, I enjoy Rust programming language and love anime culture, especially works like "Lucky Star", "Bocchi the Rock", and "Laid-Back Camp". I believe the combination of technology and art can create better products.',
        about_skills: 'Skills & Expertise',
        about_experience: 'Professional Experience',
        about_achievements: 'Achievements',
        
        // 技能标签
        skill_expert: 'Expert',
        skill_proficient: 'Proficient',
        skill_beginner: 'Beginner',
        
        // 时间线
        timeline_tsinghua: 'Tsinghua University',
        timeline_tsinghua_major: 'Computer Science & Technology · Bachelor',
        timeline_stanford: 'Stanford University',
        timeline_stanford_major: 'Computer Science · Master',
        timeline_google: 'Google',
        timeline_google_role: 'Software Engineer · Distributed Systems Development',
        timeline_openai: 'OpenAI',
        timeline_openai_role: 'Software Engineer · AI Infrastructure Development',
        
        // 成就
        achievement_tsinghua: 'Tsinghua Outstanding Graduate',
        achievement_tsinghua_year: 'Outstanding Graduate of 2014',
        achievement_mvp: 'Microsoft MVP',
        achievement_mvp_desc: 'Microsoft Most Valuable Professional',
        achievement_huawei: 'Huawei Developer Certification',
        achievement_huawei_desc: 'Senior Software Engineer Certification',
        
        // 作品展示
        works_title: 'My Works',
        work1_title: 'Modern E-commerce Platform UI Design',
        work1_desc: 'A brand new e-commerce platform interface for fashion brands, featuring clean and modern design style to optimize user shopping experience. The project includes complete user flow design, responsive layout, and brand visual identity system.',
        work2_title: 'Tech Company Official Website Development',
        work2_desc: 'Official website developed for a technology innovation company, built with React framework, featuring smooth animations, comprehensive content management system, and SEO optimization, significantly improving website traffic and conversion rates.',
        work3_title: 'Health Management Mobile App',
        work3_desc: 'Designed and developed health tracking mobile application, including exercise recording, diet management, health data analysis and other functions. Adopts Material Design principles with intuitive and user-friendly interface, highly praised by users.',
        
        // 联系方式
        contact_title: 'Contact Me',
        contact_subtitle: 'For any questions or collaboration opportunities, please feel free to contact me through the following methods',
        contact_name: 'Name',
        contact_email: 'Email',
        contact_message: 'Message',
        contact_send: 'Send Message',
        contact_email_title: 'Email',
        contact_website: 'Personal Website',
        contact_address: 'Address',
        contact_location: 'Beijing, China',
        
        // 页脚
        footer_copyright: 'Personal Portfolio. All rights reserved.',
        footer_website: 'Personal Website',
        footer_email: 'Email',
        footer_contact: 'Contact'
    }
};

// 当前语言
let currentLanguage = 'zh';

// 切换语言函数
function switchLanguage(lang) {
    if (lang === currentLanguage) return;
    
    currentLanguage = lang;
    updatePageLanguage();
    
    // 更新HTML lang属性
    document.documentElement.lang = lang === 'zh' ? 'zh-CN' : 'en';
    
    // 保存语言偏好
    localStorage.setItem('preferredLanguage', lang);
}

// 更新页面语言
function updatePageLanguage() {
    const t = translations[currentLanguage];
    
    // 更新导航栏
    document.querySelector('.logo').textContent = t.nav_portfolio;
    document.querySelector('a[href="#about"]').textContent = t.nav_about;
    document.querySelector('a[href="#works"]').textContent = t.nav_works;
    document.querySelector('a[href="#contact"]').textContent = t.nav_contact;
    
    // 更新英雄区域
    document.querySelector('.hero h1').innerHTML = `${t.hero_greeting}，<span id="name">${t.hero_title}</span>`;
    document.querySelector('.hero p').textContent = t.hero_welcome;
    document.querySelector('.hero .btn').textContent = t.hero_view_works;
    
    // 更新关于我部分
    document.querySelector('#about h2').textContent = t.about_title;
    document.querySelector('.about-text h3').textContent = t.about_role;
    document.querySelectorAll('.about-text p')[0].textContent = t.about_description1;
    document.querySelectorAll('.about-text p')[1].textContent = t.about_description2;
    document.querySelector('.skills-section h4').textContent = t.about_skills;
    document.querySelector('.timeline-section h4').textContent = t.about_experience;
    document.querySelector('.achievements-section h4').textContent = t.about_achievements;
    
    // 更新技能标签
    document.querySelectorAll('.skill-tag').forEach(tag => {
        const skillName = tag.textContent;
        if (skillName === 'Python' || skillName === 'MongoDB') {
            tag.textContent = `${skillName} (${t.skill_expert})`;
        } else if (skillName === 'Next.js' || skillName === 'ElasticSearch') {
            tag.textContent = `${skillName} (${t.skill_proficient})`;
        } else if (skillName === 'Rust') {
            tag.textContent = `${skillName} (${t.skill_beginner})`;
        }
    });
    
    // 更新时间线
    const timelineItems = document.querySelectorAll('.timeline-item');
    timelineItems[0].querySelector('h5').textContent = t.timeline_tsinghua;
    timelineItems[0].querySelector('p').textContent = t.timeline_tsinghua_major;
    timelineItems[1].querySelector('h5').textContent = t.timeline_stanford;
    timelineItems[1].querySelector('p').textContent = t.timeline_stanford_major;
    timelineItems[2].querySelector('h5').textContent = t.timeline_google;
    timelineItems[2].querySelector('p').textContent = t.timeline_google_role;
    timelineItems[3].querySelector('h5').textContent = t.timeline_openai;
    timelineItems[3].querySelector('p').textContent = t.timeline_openai_role;
    
    // 更新成就
    const achievements = document.querySelectorAll('.achievement-item');
    achievements[0].querySelector('h5').textContent = t.achievement_tsinghua;
    achievements[0].querySelector('p').textContent = t.achievement_tsinghua_year;
    achievements[1].querySelector('h5').textContent = t.achievement_mvp;
    achievements[1].querySelector('p').textContent = t.achievement_mvp_desc;
    achievements[2].querySelector('h5').textContent = t.achievement_huawei;
    achievements[2].querySelector('p').textContent = t.achievement_huawei_desc;
    
    // 更新作品展示
    document.querySelector('#works h2').textContent = t.works_title;
    const works = document.querySelectorAll('.work-item');
    works[0].querySelector('h3').textContent = t.work1_title;
    works[0].querySelector('p').textContent = t.work1_desc;
    works[1].querySelector('h3').textContent = t.work2_title;
    works[1].querySelector('p').textContent = t.work2_desc;
    works[2].querySelector('h3').textContent = t.work3_title;
    works[2].querySelector('p').textContent = t.work3_desc;
    
    // 更新联系方式
    document.querySelector('#contact h2').textContent = t.contact_title;
    document.querySelector('#contact p').textContent = t.contact_subtitle;
    document.querySelector('label[for="name"]').textContent = t.contact_name;
    document.querySelector('label[for="email"]').textContent = t.contact_email;
    document.querySelector('label[for="message"]').textContent = t.contact_message;
    document.querySelector('.contact .btn span').textContent = t.contact_send;
    
    const contactInfo = document.querySelectorAll('.info-item');
    contactInfo[0].querySelector('h4').textContent = t.contact_email_title;
    contactInfo[1].querySelector('h4').textContent = t.contact_website;
    contactInfo[2].querySelector('h4').textContent = t.contact_address;
    contactInfo[2].querySelector('p').textContent = t.contact_location;
    
    // 更新页脚
    document.querySelector('footer p').textContent = `© 2023 ${t.footer_copyright}`;
    const footerLinks = document.querySelectorAll('.social-links a');
    footerLinks[0].textContent = t.footer_website;
    footerLinks[1].textContent = t.footer_email;
    footerLinks[2].textContent = t.footer_contact;
}

// 初始化语言
function initLanguage() {
    // 检查本地存储的语言偏好
    const savedLang = localStorage.getItem('preferredLanguage');
    if (savedLang && translations[savedLang]) {
        currentLanguage = savedLang;
    } else {
        // 检测浏览器语言
        const browserLang = navigator.language || navigator.userLanguage;
        if (browserLang.startsWith('en')) {
            currentLanguage = 'en';
        }
    }
    
    updatePageLanguage();
    document.documentElement.lang = currentLanguage === 'zh' ? 'zh-CN' : 'en';
}

// 页面加载时初始化语言
document.addEventListener('DOMContentLoaded', function() {
    initLanguage();
    
    // 添加语言切换按钮事件监听
    const langButtons = document.querySelectorAll('.lang-switch');
    langButtons.forEach(button => {
        button.addEventListener('click', function() {
            const lang = this.getAttribute('data-lang');
            switchLanguage(lang);
            
            // 更新按钮状态
            langButtons.forEach(btn => btn.classList.remove('active'));
            this.classList.add('active');
        });
    });
});